/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function(){
	$.validator.addMethod('price', function(value, element) {
		return this.optional(element) || (parseInt(value) > 0);
	}, messages.price_must_be_large_than_0);
	$courseDetailErrorMessages = {
		'data[CourseDetail][zip01]' : {
			required: messages.this_field_is_requied,
			number: messages.must_be_numeric
		},
		'data[CourseDetail][zip02]': {
			required: messages.this_field_is_requied,
			number: messages.must_be_numeric
		},
		'data[CourseDetail][address01]': {
			required: messages.this_field_is_requied
		},
		'data[CourseDetail][address02]': {
			required: messages.this_field_is_requied,
			number: messages.price_must_be_numeric
		},
		'data[CourseDetail][place_name]': {
			required: messages.this_field_is_requied
		},
		'data[CourseDetail][attend_total]': {
			required: messages.this_field_is_requied,
			number: messages.must_be_numeric
		},
		'data[CourseDetail][price]': {
			required: messages.this_field_is_requied,
			number: messages.must_be_numeric
		}
	};
	$('#confirmCourse').click(function(){
		$('#CourseDetailForm').validate({
			errorElement: "div",
			messages: $courseDetailErrorMessages,
			errorPlacement: function(error, element){
				if(element.attr('id') == "price"){
					error.insertAfter(".br-price");
				}else if(element.attr('id') == "zip01"){
					error.insertAfter("#zip02");
				}else{
					error.insertAfter(element);
				}
			}
		});
		if($('#CourseDetailForm').valid()){
			var dateCourse = $('#year').val() +' / ' + $('#month').val() + ' / ' + $('#day').val() + ' ';
			$('#confirm_date').text(dateCourse);
			var hourCourse = $('#openHour option:selected').text() + ':' + $('#openMinute').val() + ' - ' + $('#closeHour').val() + ':' + $('#closeMinute').val();
			$('#confirm_hour').text(hourCourse);
			$('#confirm_area').text($('#area option:selected').text() + ' ');
			$('#confirm_zipcode').text('〒 ' + $('#zip01').val() + ' - ' + $('#zip02').val());
			$('#confirm_city').text( $('#city').val());
			if($('#address').val() !=''){
				$('#confirm_address').html( $('#address').val());
			}else{
				$('#confirm_address').html( $('#address').val() + '<br />');
			}
			$('#confirm_place').text($('#placeName').val());
			if($('input[name="data[CourseDetail][address_flg]"]:checked').val() == 1){
				$('#confirm_address_display').text('全員に公開');
			}else{
				$('#confirm_address_display').text('予約者のみ公開');
			}
			$('#confirm_attend_total').text($('#attendTotal').val());
			$('#confirm_price').text($('#price').val() + '円');
			$('#confirm_notice').text($('#notice').val());
			$('#step01').hide();
			$('#step02').show();
			return false;
		}
		return false;
	});
	$('#correct').click(function(){
		$('#step01').show();
		$('#step02').hide();
	});
	$('#submit_form').click(function(){
		$('#CourseDetailForm').submit();
	});
});

